<?php defined('InNcPHP') or exit('Access Invalid!');?>

<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/jquery.ui.js"></script>
<script type="text/javascript" src="<?php echo RESOURCE_URL;?>/common/jquery-ui/i18n/zh-CN.js" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="<?php echo RESOURCE_URL;?>/common/jquery-ui/themes/ui-lightness/jquery.ui.css"  />
<style>
    .hide { display: none; }
    .layui-layer-title{color: red;}
</style>
<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <h3><?php echo $lang['order_index'];?></h3>
            <?php echo $output['top_link'];?>
        </div>
    </div>
    <div class="fixed-empty"></div>
    <!--  搜索表单  -->
    <form method="get" name="formSearch" id="formSearch">
        <input type="hidden" value="order" name="act">
        <input type="hidden" value="index" name="op">
        <table class="tb-type1 noborder search">
            <tbody>
            <tr>
                <th><label> <?php echo $lang['order_index_order_sn'];?></label></th>
                <td><input type="text" name="search_sn" value="<?php echo $output['search']['search_sn']; ?>" class="txt"></td>
                <th><label><?php echo $lang['order_index_addtime'];?></label></th>
                <td><input type="text" name="search_stime" value="<?php echo $output['search']['search_stime']; ?>" id="search_stime" class="txt date"></td>
                <td><input type="text" name="search_etime" value="<?php echo $output['search']['search_etime']; ?>" id="search_etime" class="txt date"></td>
            </tr>
            <tr>
                <th><label> <?php echo $lang['order_index_merchant'];?></label></th>
                <td>
                    <select name="search_merchant">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['merchants'])): ?>
                            <?php foreach ($output['merchants'] as $k => $v): ?>
                                <option value="<?php echo $v['merchant_id']; ?>" <?php echo $output['search']['search_merchant'] == $v['merchant_id'] ? 'selected' : ''; ?>><?php echo $v['mc_shop_name']; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo $lang['order_index_status'];?></label></th>
                <td>
                    <select name="search_status">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['status'])): ?>
                            <?php foreach ($output['status'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo $output['search']['search_status'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <th><label> <?php echo '订单类型';?></label></th>
                <td>
                    <select name="order_type">
                        <option value=""><?php echo $lang['nc_please_choose'];?>...</option>
                        <?php if (is_array($output['order_type'])): ?>
                            <?php foreach ($output['order_type'] as $k => $v): ?>
                                <option value="<?php echo $k; ?>" <?php echo $output['search']['order_type'] == $k ? 'selected' : ''; ?>><?php echo $v; ?></option>
                            <?php endforeach; ?>
                        <?php endif; ?>
                    </select>
                </td>
                <td>
                    <a href="javascript:void(0);" onclick="$('#formSearch').submit();" class="btn-search">&nbsp;</a>
                    <?php if ($output['search']['search_sn'] || $output['search']['search_stime'] || $output['search']['search_etime'] || $output['search']['search_merchant'] || $output['search']['search_status']): ?>
                    <a href="index.php?act=order&op=index" class="btns "><span><?php echo $lang['nc_cancel_search']?></span></a>

                    <?php endif; ?>
                </td>
            </tr>
            </tbody>
        </table>
    </form>

    <a class="m-btn blue-stripe mini <?php echo empty($_GET['search_status'])?'checked':'' ?> " onclick="parent.openItem('index,order,trade');" href="#">全部订单</a>
    <a class="m-btn yellow-stripe mini <?php echo ($_GET['search_status']==10)?'checked':'' ?>" onclick="parent.openItem('index,order,trade,search_status=10');"  href="#">待支付</a>
    <a class="m-btn red-stripe mini  <?php echo ($_GET['search_status']==20)?'checked':'' ?> " onclick="parent.openItem('index,order,trade,search_status=20');" href="#">待使用</a>
    <a class="m-btn green-stripe mini <?php echo ($_GET['search_status']==21)?'checked':'' ?>" onclick="parent.openItem('index,order,trade,search_status=21');"  href="#">已完成</a>
    <a class="m-btn black-stripe mini <?php echo ($_GET['search_status']==30)?'checked':'' ?>" onclick="parent.openItem('index,order,trade,search_status=30');" href="#">已取消</a>
    <a class="m-btn red-stripe mini <?php echo ($_GET['search_status']==31)?'checked':'' ?>" onclick="parent.openItem('index,order,trade,search_status=31');" href="#">退款中</a>
    <a class="m-btn green-stripe mini <?php echo ($_GET['search_status']==32)?'checked':'' ?>" onclick="parent.openItem('index,order,trade,search_status=32');" href="#">已退款</a>

    <div style="text-align:right;"><a class="btns" target="_blank" href="index.php?<?php echo $_SERVER['QUERY_STRING'];?>&op=export"><span><?php echo $lang['nc_export'];?>Excel</span></a></div>
    <!--  显示列表  -->
    <table class="table tb-type2 nobdb">
        <thead>
        <tr class="thead">
            <th><?php echo $lang['order_index_order_sn']?></th>
            <th class="align-center"><?php echo $lang['order_index_title']?></th>
            <th class="align-center"><?php echo $lang['order_index_nickname']?></th>
            <th><?php echo $lang['order_index_content']?></th>
            <th class="align-center"><?php echo $lang['order_index_merchant']?></th>
            <th class="align-center">订单类型</th>
            <th class="align-center">支付方式</th>
            <th class="align-center"><?php echo $lang['order_index_money']; ?></th>
            <th class="align-center"><?php echo $lang['order_index_addtime'];?></th>
            <th class="align-center"><?php echo $lang['order_index_status']?></th>
            <th class="align-center"><?php echo $lang['nc_handle'];?></th>
        </tr>
        <tbody>
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <?php foreach($output['orders'] as $k => $v){ ?>
                <tr class="hover member">
                    <td><?php echo $v['order_sn']; ?></td>
                    <td class="align-center" style="width:200px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;display: block; "><?php echo $v['ticket_title']; ?></td>
                    <td class="align-center"><?php echo $v['mobile']; ?></td>
                    <td >
                        <?php foreach ($v['sku'] as $sku): ?>
                            <?php if($v['order_type']==2) {?>
                            <?php echo $sku['type_name'].'x'.$sku['ot_num'].';'; ?>
                            <?php }elseif($v['order_type']==1){?>
                            <?php echo $v['spec_name'].'x'.$sku['oh_num'].';'; ?>
                            <?php }else{ ?>
                                <span style="width:200px;overflow: hidden; white-space: nowrap; text-overflow: ellipsis;display: block; "><?php echo $v['spec_name'] ?></span>x<span><?php echo $sku['og_num']; ?></span>
                            <?php } ?>
                        <?php endforeach; ?>
                    </td>
                    <td class="align-center"><?php echo $v['mc_shop_name']; ?></td>
                    <td class="align-center"><?php echo $output['order_type'][$v['order_type']]; ?></td>
                    <td class="align-center"><?php echo $output['pay_type'][$v['pay_type']]; ?></td>
                    <td class="align-center"><?php echo $v['need_pay']; ?></td>
                    <td class="align-center"><?php echo date('Y-m-d H:i:s',$v['add_time']); ?></td>
                    <td class="align-center"><?php echo $output['status'][$v['order_status']]; ?></td>
                    <td class="align-center">
                        <a href="index.php?act=order&op=detail&order_id=<?php echo $v['order_id']; ?>">查看</a>
                        <?php if($v['order_type']==1 && $v['order_status']==20 && $v['if_examine'] ==0): ?>
                            <a href="###" onclick="examine_order(<?php echo $v['order_id']; ?>, $(this));">审核订单</a>
                        <?php endif; ?>
                        <?php if ($v['order_status'] == 10): ?>
                        <!--<a href="###" onclick="check_money(<?php /*echo $v['order_id']; */?>, $(this));">确认收款</a>-->
                        <?php endif; ?>
                    </td>
                </tr>
            <?php } ?>

        <?php }else { ?>
            <tr class="no_data">
                <td colspan="11"><?php echo $lang['nc_no_record']?></td>
            </tr>
        <?php } ?>
        </tbody>
        <tfoot class="tfoot">
        <?php if(!empty($output['orders']) && is_array($output['orders'])){ ?>
            <tr>
                <td colspan="16">
                    <div class="pagination"> <?php echo $output['page'];?> </div>
                </td>
            </tr>
        <?php } ?>
        </tfoot>
    </table>
<style>
    .item{border-bottom: 1px solid #EAEAEA;}
    .item div{display: inline-block;line-height: 40px;}
    .item .title{width: 100px;}
</style>
    <form id="examine_order" method="post" class="hide">
        <input type="hidden" name="order_id">
        <div class="table tb-type2">
            <div class="item">
                <div class="required title"><label class="validation">房型名称:</label></div>
                <div style="display: inline-block" class="vatop rowform spec_name">不知道</div>
            </div>

            <div class="item">
                <div class="required title"><label class="validation">预定数量:</label></div>
                <div style="display: inline-block" class="vatop rowform oh_num">2间</div>
            </div>
            <div class="item">
                <div class="required title"><label class="validation">手机号:</label></div>
                <div style="display: inline-block" class="vatop rowform mobile"></div>
            </div>
            <div class="item">
                <div class="required title"><label class="validation">入驻时间:</label></div>
                <div style="display: inline-block" class="vatop rowform startdate"></div>
            </div>
            <div class="item">
                <div class="required title"><label class="validation">离店时间:</label></div>
                <div style="display: inline-block" class="vatop rowform enddate"></div>
            </div>
            <div class="item">
                <div class="required title"><label class="validation">合计几晚:</label></div>
                <div style="display: inline-block" class="vatop rowform numdate">不知道</div>
            </div>
            <input name="if_examine" type="hidden" value="0" >
            <!--<tr class="noborder">
                <td class="vatop rowform">
                <select id="if_examine" name="if_examine" class="class-select">
                    <option value="1">确认入驻</option>
                    <option value="2">拒绝此单</option>
                </select>
            </td>
            </tr>-->
            <tfoot>
            <tr>
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="editSubmit"><span>接受</span></a></td>
                <td colspan="2"><a href="JavaScript:void(0);" class="btn" id="edit_mo_Submit"><span>拒绝</span></a></td>
            </tr>
            </tfoot>
        </div>
    </form>
</div>
<script>
    //开始日期
    $('#search_stime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_etime").datepicker("option", "minDate", selectedDate);
        }
    });
    //结束日期
    $('#search_etime').datepicker({
        dateFormat: 'yy-mm-dd',
        onClose: function(selectedDate) {
            $("#search_stime").datepicker("option", "maxDate", selectedDate);
        }
    });
    //确认收款
    function check_money(orderId, obj) {
        layer.confirm('确认收到款项？', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        }, function (index) {
            $.post('index.php?act=order&op=check_money', {id:orderId},function (data) {
                if (data.res) {
                    obj.parent().prev().text('<?php echo $output['status']['20']; ?>');
                    obj.remove();
                } else {
                    layer.alert('确认失败');
                }
                layer.close(index);
            }, 'json');
        });
    }
    var editForm = $('#examine_order');
    //确认是否有房型
    function examine_order(orderId , obj) {
        $.post('index.php?act=order&op=ajax_get_order', {id: orderId}, function (data) {
            editForm.find('input[name="order_id"]').val(data.order_id);
            editForm.find(".spec_name").text(data.spec_name);
            editForm.find(".mobile").text(data.member_phone);
            editForm.find(".startdate").text(data.sku.startdate);
            editForm.find(".enddate").text(data.sku.enddate);
            editForm.find(".numdate").text(data.sku.numdate);
            editForm.find(".oh_num").text(data.sku.oh_num+'间');
            layer.open({
                type: 1,
                title: '审核订单(请根据实际情况操作,若无房请拒绝该订单,订单金额将原路返回至顾客账户中）',
                area: ['700px', '410px'],
                content: editForm,
                cancel: function () {
                    $('label.error').hide();
                    //editForm.find('input.error').removeClass('error');
                }
            });
        }, 'json');
    }


    //提交编辑表单
    $("#editSubmit").click(function(){
        editForm.find('input[name="if_examine"]').val(1);
        layer.confirm('确认您的审核操作？', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        },function(index){
            $.post('index.php?act=order&op=examine_order',editForm.serialize(),function(data){
                if(data.res){
                    layer.alert('<?php echo $lang['nc_common_update_succ']; ?>', function () {
                        location.reload();
                    });
                }else{
                    layer.alert(data._msg);
                }
            },'json');
            layer.close(index);
        })
    });
    //提交编辑表单
    $("#edit_mo_Submit").click(function(){
        editForm.find('input[name="if_examine"]').val(0);
        layer.confirm('确认您的审核操作？', {
            btn: ['<?php echo $lang['nc_yes']; ?>', '<?php echo $lang['nc_no']; ?>']
        },function(index){
            $.post('index.php?act=order&op=examine_order',editForm.serialize(),function(data){
                if(data.res){
                    layer.alert('<?php echo $lang['nc_common_update_succ']; ?>', function () {
                        location.reload();
                    });
                }else{
                    layer.alert(data._msg);
                }
            },'json');
            layer.close(index);
        })
    });
    //
</script>
